package com.qf.controller;

import com.github.pagehelper.PageHelper;
import com.qf.pojo.Car;
import com.qf.pojo.Message;
import com.qf.pojo.User;
import com.qf.service.CarService;
import com.qf.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/car")
public class CarController {
    @Autowired
    private CarService carService;

    @RequestMapping(method = RequestMethod.GET)
    @ResponseBody
    public Message<Car> selectAll(int page, int limit){
    PageHelper.startPage(page,limit);
    List<Car> carList = carService.selectAll();
    Message<Car> message = new Message<Car>();
    message.setData(carList);
    message.setCount(100);
    return message;
  }


    @PostMapping(value = "/del")
    @ResponseBody
    public int del(HttpServletRequest request){
        String cids = request.getParameter("cid");
        Integer cid = Integer.valueOf(cids);
        int res = carService.delete(cid);
        return res;
    }


    @RequestMapping(value = "/one")
    @ResponseBody
    public Car one(HttpServletRequest request){
        Car car = carService.selectOne(1);
        return car;
    }
}
